package cn.edu.tsinghua.card;

import static cn.edu.tsinghua.card.NamePinyinChecker.INVALID_CHINESE_NAME;
import static cn.edu.tsinghua.card.NamePinyinChecker.INVALID_ENGLISH_NAME;
import static cn.edu.tsinghua.card.NamePinyinChecker.NORMAL;
import static cn.edu.tsinghua.card.NamePinyinChecker.UNMATCHED_PINYIN;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;
import java.util.Map.Entry;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class NamePinyinCheckerTestCase {
	public static final Logger LOGGER = LoggerFactory.getLogger(NamePinyinCheckerTestCase.class);
	
	public static void check(String cnname, String enname, Integer result) {
		Entry<Integer, String> res = NamePinyinChecker.check(cnname, enname);
		LOGGER.debug(String.format("%d: %s", res.getKey(), res.getValue()));
		assertEquals(result, res.getKey());		
	}
	
	@Test
	void testNormalChineseName() {
		check("陈强", "Chen Qiang", NORMAL);
		check("刘乃嘉", "Liu Naijia", NORMAL);
		check("欧阳沁", "Ouyang Qin", NORMAL);
		check("欧阳荣彬", "Ouyang Rongbin", NORMAL);
		check("吉·青柯莫", "Ji Qingkemo", NORMAL);
		check("吕晓杰", "Lyu Xiaojie", NORMAL);
	}
	
	@Test
	void testInvalidChineseName() {
		check("", "", INVALID_CHINESE_NAME);
		check("张3", "Zhang San", INVALID_CHINESE_NAME);
		check("张A", "Zhang A", INVALID_CHINESE_NAME);
		check("张　三", "Zhang San", INVALID_CHINESE_NAME);
		check("吉··青柯莫", "Ji Qingkemo", INVALID_CHINESE_NAME);
	}
	
	@Test
	void testInvalidEnglishName() {
		check("陈强", "Chen Qiang ", INVALID_ENGLISH_NAME);
		check("陈强", " Chen Qiang", INVALID_ENGLISH_NAME);
		check("陈强", "Chen  Qiang", INVALID_ENGLISH_NAME);
		check("陈强", "ChenQiang", INVALID_ENGLISH_NAME);
		check("陈强", "Chen, Qiang", INVALID_ENGLISH_NAME);
		check("陈强", "CHEN Qiang", INVALID_ENGLISH_NAME);
	}
	
	@Test
	void testUnmatchedChineseName() {
		check("陈强", "Chen Qinag", UNMATCHED_PINYIN);
		check("陈强", "Chen Qiang Ha", UNMATCHED_PINYIN);
	}
	
	@Test
	void testGeneralPinyinSpelling() {
		for(String name: List.of("陈强", "刘乃嘉", "欧阳荣彬", "闾丘露薇", "皇甫晓东", "李王乐彤", "阿沛·阿旺晋美", "吉·青柯莫")) {
			LOGGER.debug(String.format("%s: %s", name, NamePinyinChecker.getPinyinSpelling(name)));
		}
	}

}
